package com.jnxx.basic.service.impl;

import com.jnxx.basic.mapper.BaseMapper;
import com.jnxx.basic.query.BaseQuery;
import com.jnxx.basic.query.PageInfo;
import com.jnxx.basic.service.IBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {

    @Autowired
    private BaseMapper<T> baseMapper;

    @Override
    public List<T> findAll() {
        return baseMapper.findAll();
    }

    @Override
    public T findOne(Long id) {
        return baseMapper.findOne(id);
    }

    @Transactional
    @Override
    public void add(T t) {
        baseMapper.add(t);
    }

    @Transactional
    @Override
    public void update(T t) {
        baseMapper.update(t);
    }

    @Transactional
    @Override
    public void del(Long id) {
        baseMapper.del(id);
    }

    @Transactional
    @Override
    public void batchDel(List<Long> ids) {
        baseMapper.batchDel(ids);
    }

    @Override
    public PageInfo<T> page(BaseQuery baseQuery) {
        Integer count = baseMapper.findCount(baseQuery);
        List<T> list =  baseMapper.page(baseQuery);
        return new PageInfo<>(count,list,baseQuery.getPageSize());
    }
}
